home *** CD-ROM | disk | FTP | other *** search
/ Maclife 157 / MACLIFE157-2001-09.ISO.7z / MACLIFE157-2001-09.ISO / Linux / MacOS Tools / Other / BootX 1.1.3 (for Old Mac OS) / Sources / inc / elf_loader_defs.h < prev    next >
Text File  |  2001-07-23  |  14KB  |  522 lines

  1. #ifndef _MODIFIED_LINUX_ELF_H
  2. #define _MODIFIED_LINUX_ELF_H
  3.  
  4. #include "linux_type_defs.h"
  5.  
  6. // from asm-ppc/elf.h
  7. #define ELF_ARCH    EM_PPC
  8. #define ELF_CLASS    ELFCLASS32
  9. #define ELF_DATA    ELFDATA2MSB
  10.  
  11.  
  12. /* 32-bit ELF base types. */
  13. typedef __u32    Elf32_Addr;
  14. typedef __u16    Elf32_Half;
  15. typedef __u32    Elf32_Off;
  16. typedef __s32    Elf32_Sword;
  17. typedef __u32    Elf32_Word;
  18.  
  19. /* 64-bit ELF base types. */
  20. typedef __u64    Elf64_Addr;
  21. typedef __u16    Elf64_Half;
  22. typedef __s16    Elf64_SHalf;
  23. typedef __u64    Elf64_Off;
  24. typedef __s64    Elf64_Sword;
  25. typedef __u64    Elf64_Word;
  26.  
  27. /* These constants are for the segment types stored in the image headers */
  28. #define PT_NULL    0
  29. #define PT_LOAD    1
  30. #define PT_DYNAMIC 2
  31. #define PT_INTERP  3
  32. #define PT_NOTE    4
  33. #define PT_SHLIB   5
  34. #define PT_PHDR    6
  35. #define PT_LOPROC  0x70000000
  36. #define PT_HIPROC  0x7fffffff
  37.  
  38. /* These constants define the different elf file types */
  39. #define ET_NONE   0
  40. #define ET_REL    1
  41. #define ET_EXEC   2
  42. #define ET_DYN    3
  43. #define ET_CORE   4
  44. #define ET_LOPROC 5
  45. #define ET_HIPROC 6
  46.  
  47. /* These constants define the various ELF target machines */
  48. #define EM_NONE  0
  49. #define EM_M32   1
  50. #define EM_SPARC 2
  51. #define EM_386   3
  52. #define EM_68K   4
  53. #define EM_88K   5
  54. #define EM_486   6   /* Perhaps disused */
  55. #define EM_860   7
  56.  
  57. #define EM_MIPS        8    /* MIPS R3000 (officially, big-endian only) */
  58.  
  59. #define EM_MIPS_RS4_BE 10    /* MIPS R4000 big-endian */
  60.  
  61. #define EM_PARISC      15    /* HPPA */
  62.  
  63. #define EM_SPARC32PLUS 18    /* Sun's "v8plus" */
  64.  
  65. #define EM_PPC           20    /* PowerPC */
  66.  
  67. #define EM_SPARCV9     43    /* SPARC v9 64-bit */
  68.  
  69. /*
  70.  * This is an interim value that we will use until the committee comes
  71.  * up with a final number.
  72.  */
  73. #define EM_ALPHA    0x9026
  74.  
  75.  
  76. /* This is the info that is needed to parse the dynamic section of the file */
  77. #define DT_NULL        0
  78. #define DT_NEEDED    1
  79. #define DT_PLTRELSZ    2
  80. #define DT_PLTGOT    3
  81. #define DT_HASH        4
  82. #define DT_STRTAB    5
  83. #define DT_SYMTAB    6
  84. #define DT_RELA        7
  85. #define DT_RELASZ    8
  86. #define DT_RELAENT    9
  87. #define DT_STRSZ    10
  88. #define DT_SYMENT    11
  89. #define DT_INIT        12
  90. #define DT_FINI        13
  91. #define DT_SONAME    14
  92. #define DT_RPATH     15
  93. #define DT_SYMBOLIC    16
  94. #define DT_REL            17
  95. #define DT_RELSZ    18
  96. #define DT_RELENT    19
  97. #define DT_PLTREL    20
  98. #define DT_DEBUG    21
  99. #define DT_TEXTREL    22
  100. #define DT_JMPREL    23
  101. #define DT_LOPROC    0x70000000
  102. #define DT_HIPROC    0x7fffffff
  103.  
  104. /* This info is needed when parsing the symbol table */
  105. #define STB_LOCAL  0
  106. #define STB_GLOBAL 1
  107. #define STB_WEAK   2
  108.  
  109. #define STT_NOTYPE  0
  110. #define STT_OBJECT  1
  111. #define STT_FUNC    2
  112. #define STT_SECTION 3
  113. #define STT_FILE    4
  114.  
  115. #define ELF32_ST_BIND(x) ((x) >> 4)
  116. #define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
  117.  
  118. /* Symbolic values for the entries in the auxiliary table
  119.    put on the initial stack */
  120. #define AT_NULL   0    /* end of vector */
  121. #define AT_IGNORE 1    /* entry should be ignored */
  122. #define AT_EXECFD 2    /* file descriptor of program */
  123. #define AT_PHDR   3    /* program headers for program */
  124. #define AT_PHENT  4    /* size of program header entry */
  125. #define AT_PHNUM  5    /* number of program headers */
  126. #define AT_PAGESZ 6    /* system page size */
  127. #define AT_BASE   7    /* base address of interpreter */
  128. #define AT_FLAGS  8    /* flags */
  129. #define AT_ENTRY  9    /* entry point of program */
  130. #define AT_NOTELF 10    /* program is not ELF */
  131. #define AT_UID    11    /* real uid */
  132. #define AT_EUID   12    /* effective uid */
  133. #define AT_GID    13    /* real gid */
  134. #define AT_EGID   14    /* effective gid */
  135. #define AT_PLATFORM 15  /* string identifying CPU for optimizations */
  136. #define AT_HWCAP  16    /* arch dependent hints at CPU capabilities */
  137.  
  138. typedef struct dynamic{
  139.   Elf32_Sword d_tag;
  140.   union{
  141.     Elf32_Sword    d_val;
  142.     Elf32_Addr    d_ptr;
  143.   } d_un;
  144. } Elf32_Dyn;
  145.  
  146. typedef struct {
  147.   Elf64_Word d_tag;        /* entry tag value */
  148.   union {
  149.     Elf64_Word d_val;
  150.     Elf64_Word d_ptr;
  151.   } d_un;
  152. } Elf64_Dyn;
  153.  
  154. /* The following are used with relocations */
  155. #define ELF32_R_SYM(x) ((x) >> 8)
  156. #define ELF32_R_TYPE(x) ((x) & 0xff)
  157.  
  158. #define R_386_NONE    0
  159. #define R_386_32    1
  160. #define R_386_PC32    2
  161. #define R_386_GOT32    3
  162. #define R_386_PLT32    4
  163. #define R_386_COPY    5
  164. #define R_386_GLOB_DAT    6
  165. #define R_386_JMP_SLOT    7
  166. #define R_386_RELATIVE    8
  167. #define R_386_GOTOFF    9
  168. #define R_386_GOTPC    10
  169. #define R_386_NUM    11
  170.  
  171. /*
  172.  * Sparc ELF relocation types
  173.  */
  174. #define    R_SPARC_NONE        0
  175. #define    R_SPARC_8        1
  176. #define    R_SPARC_16        2
  177. #define    R_SPARC_32        3
  178. #define    R_SPARC_DISP8        4
  179. #define    R_SPARC_DISP16        5
  180. #define    R_SPARC_DISP32        6
  181. #define    R_SPARC_WDISP30        7
  182. #define    R_SPARC_WDISP22        8
  183. #define    R_SPARC_HI22        9
  184. #define    R_SPARC_22        10
  185. #define    R_SPARC_13        11
  186. #define    R_SPARC_LO10        12
  187. #define    R_SPARC_GOT10        13
  188. #define    R_SPARC_GOT13        14
  189. #define    R_SPARC_GOT22        15
  190. #define    R_SPARC_PC10        16
  191. #define    R_SPARC_PC22        17
  192. #define    R_SPARC_WPLT30        18
  193. #define    R_SPARC_COPY        19
  194. #define    R_SPARC_GLOB_DAT    20
  195. #define    R_SPARC_JMP_SLOT    21
  196. #define    R_SPARC_RELATIVE    22
  197. #define    R_SPARC_UA32        23
  198. #define R_SPARC_PLT32        24
  199. #define R_SPARC_HIPLT22        25
  200. #define R_SPARC_LOPLT10        26
  201. #define R_SPARC_PCPLT32        27
  202. #define R_SPARC_PCPLT22        28
  203. #define R_SPARC_PCPLT10        29
  204. #define R_SPARC_10        30
  205. #define R_SPARC_11        31
  206. #define R_SPARC_WDISP16        40
  207. #define R_SPARC_WDISP19        41
  208. #define R_SPARC_7        43
  209. #define R_SPARC_5        44
  210. #define R_SPARC_6        45
  211.  
  212. /* Bits present in AT_HWCAP, primarily for Sparc32.  */
  213.  
  214. #define HWCAP_SPARC_FLUSH       1    /* CPU supports flush instruction. */
  215. #define HWCAP_SPARC_STBAR       2
  216. #define HWCAP_SPARC_SWAP        4
  217. #define HWCAP_SPARC_MULDIV      8
  218. #define HWCAP_SPARC_V9        16
  219.  
  220.  
  221. /*
  222.  * 68k ELF relocation types
  223.  */
  224. #define R_68K_NONE    0
  225. #define R_68K_32    1
  226. #define R_68K_16    2
  227. #define R_68K_8        3
  228. #define R_68K_PC32    4
  229. #define R_68K_PC16    5
  230. #define R_68K_PC8    6
  231. #define R_68K_GOT32    7
  232. #define R_68K_GOT16    8
  233. #define R_68K_GOT8    9
  234. #define R_68K_GOT32O    10
  235. #define R_68K_GOT16O    11
  236. #define R_68K_GOT8O    12
  237. #define R_68K_PLT32    13
  238. #define R_68K_PLT16    14
  239. #define R_68K_PLT8    15
  240. #define R_68K_PLT32O    16
  241. #define R_68K_PLT16O    17
  242. #define R_68K_PLT8O    18
  243. #define R_68K_COPY    19
  244. #define R_68K_GLOB_DAT    20
  245. #define R_68K_JMP_SLOT    21
  246. #define R_68K_RELATIVE    22
  247.  
  248. /*
  249.  * Alpha ELF relocation types
  250.  */
  251. #define R_ALPHA_NONE            0       /* No reloc */
  252. #define R_ALPHA_REFLONG         1       /* Direct 32 bit */
  253. #define R_ALPHA_REFQUAD         2       /* Direct 64 bit */
  254. #define R_ALPHA_GPREL32         3       /* GP relative 32 bit */
  255. #define R_ALPHA_LITERAL         4       /* GP relative 16 bit w/optimization */
  256. #define R_ALPHA_LITUSE          5       /* Optimization hint for LITERAL */
  257. #define R_ALPHA_GPDISP          6       /* Add displacement to GP */
  258. #define R_ALPHA_BRADDR          7       /* PC+4 relative 23 bit shifted */
  259. #define R_ALPHA_HINT            8       /* PC+4 relative 16 bit shifted */
  260. #define R_ALPHA_SREL16          9       /* PC relative 16 bit */
  261. #define R_ALPHA_SREL32          10      /* PC relative 32 bit */
  262. #define R_ALPHA_SREL64          11      /* PC relative 64 bit */
  263. #define R_ALPHA_OP_PUSH         12      /* OP stack push */
  264. #define R_ALPHA_OP_STORE        13      /* OP stack pop and store */
  265. #define R_ALPHA_OP_PSUB         14      /* OP stack subtract */
  266. #define R_ALPHA_OP_PRSHIFT      15      /* OP stack right shift */
  267. #define R_ALPHA_GPVALUE         16
  268. #define R_ALPHA_GPRELHIGH       17
  269. #define R_ALPHA_GPRELLOW        18
  270. #define R_ALPHA_IMMED_GP_16     19
  271. #define R_ALPHA_IMMED_GP_HI32   20
  272. #define R_ALPHA_IMMED_SCN_HI32  21
  273. #define R_ALPHA_IMMED_BR_HI32   22
  274. #define R_ALPHA_IMMED_LO32      23
  275. #define R_ALPHA_COPY            24      /* Copy symbol at runtime */
  276. #define R_ALPHA_GLOB_DAT        25      /* Create GOT entry */
  277. #define R_ALPHA_JMP_SLOT        26      /* Create PLT entry */
  278. #define R_ALPHA_RELATIVE        27      /* Adjust by program base */
  279.  
  280. /* Legal values for e_flags field of Elf64_Ehdr.  */
  281.  
  282. #define EF_ALPHA_32BIT        1    /* All addresses are below 2GB */
  283.  
  284.  
  285. typedef struct elf32_rel {
  286.   Elf32_Addr    r_offset;
  287.   Elf32_Word    r_info;
  288. } Elf32_Rel;
  289.  
  290. typedef struct elf64_rel {
  291.   Elf64_Addr r_offset;    /* Location at which to apply the action */
  292.   Elf64_Word r_info;    /* index and type of relocation */
  293. } Elf64_Rel;
  294.  
  295. typedef struct elf32_rela{
  296.   Elf32_Addr    r_offset;
  297.   Elf32_Word    r_info;
  298.   Elf32_Sword    r_addend;
  299. } Elf32_Rela;
  300.  
  301. typedef struct elf64_rela {
  302.   Elf64_Addr r_offset;    /* Location at which to apply the action */
  303.   Elf64_Word r_info;    /* index and type of relocation */
  304.   Elf64_Word r_addend;    /* Constant addend used to compute value */
  305. } Elf64_Rela;
  306.  
  307. typedef struct elf32_sym{
  308.   Elf32_Word    st_name;
  309.   Elf32_Addr    st_value;
  310.   Elf32_Word    st_size;
  311.   unsigned char    st_info;
  312.   unsigned char    st_other;
  313.   Elf32_Half    st_shndx;
  314. } Elf32_Sym;
  315.  
  316. typedef struct elf64_sym {
  317.   Elf32_Word st_name;        /* Symbol name, index in string tbl (yes, Elf32) */
  318.   unsigned char    st_info;    /* Type and binding attributes */
  319.   unsigned char    st_other;    /* No defined meaning, 0 */
  320.   Elf64_Half st_shndx;        /* Associated section index */
  321.   Elf64_Addr st_value;        /* Value of the symbol */
  322.   Elf64_Word st_size;        /* Associated symbol size */
  323. } Elf64_Sym;
  324.  
  325.  
  326. #define EI_NIDENT    16
  327.  
  328. typedef struct elf32_hdr{
  329.   unsigned char    e_ident[EI_NIDENT];
  330.   Elf32_Half    e_type;
  331.   Elf32_Half    e_machine;
  332.   Elf32_Word    e_version;
  333.   Elf32_Addr    e_entry;  /* Entry point */
  334.   Elf32_Off    e_phoff;
  335.   Elf32_Off    e_shoff;
  336.   Elf32_Word    e_flags;
  337.   Elf32_Half    e_ehsize;
  338.   Elf32_Half    e_phentsize;
  339.   Elf32_Half    e_phnum;
  340.   Elf32_Half    e_shentsize;
  341.   Elf32_Half    e_shnum;
  342.   Elf32_Half    e_shstrndx;
  343. } Elf32_Ehdr;
  344.  
  345. typedef struct elf64_hdr {
  346.   unsigned char    e_ident[16];        /* ELF "magic number" */
  347.   Elf64_SHalf e_type;
  348.   Elf64_Half e_machine;
  349.   __s32 e_version;
  350.   Elf64_Addr e_entry;        /* Entry point virtual address */
  351.   Elf64_Off e_phoff;        /* Program header table file offset */
  352.   Elf64_Off e_shoff;        /* Section header table file offset */
  353.   __s32 e_flags;
  354.   Elf64_SHalf e_ehsize;
  355.   Elf64_SHalf e_phentsize;
  356.   Elf64_SHalf e_phnum;
  357.   Elf64_SHalf e_shentsize;
  358.   Elf64_SHalf e_shnum;
  359.   Elf64_SHalf e_shstrndx;
  360. } Elf64_Ehdr;
  361.  
  362. /* These constants define the permissions on sections in the program
  363.    header, p_flags. */
  364. #define PF_R        0x4
  365. #define PF_W        0x2
  366. #define PF_X        0x1
  367.  
  368. typedef struct elf32_phdr{
  369.   Elf32_Word    p_type;
  370.   Elf32_Off    p_offset;
  371.   Elf32_Addr    p_vaddr;
  372.   Elf32_Addr    p_paddr;
  373.   Elf32_Word    p_filesz;
  374.   Elf32_Word    p_memsz;
  375.   Elf32_Word    p_flags;
  376.   Elf32_Word    p_align;
  377. } Elf32_Phdr;
  378.  
  379. typedef struct elf64_phdr {
  380.   __s32 p_type;
  381.   __s32 p_flags;
  382.   Elf64_Off p_offset;        /* Segment file offset */
  383.   Elf64_Addr p_vaddr;        /* Segment virtual address */
  384.   Elf64_Addr p_paddr;        /* Segment physical address */
  385.   Elf64_Word p_filesz;        /* Segment size in file */
  386.   Elf64_Word p_memsz;        /* Segment size in memory */
  387.   Elf64_Word p_align;        /* Segment alignment, file & memory */
  388. } Elf64_Phdr;
  389.  
  390. /* sh_type */
  391. #define SHT_NULL    0
  392. #define SHT_PROGBITS    1
  393. #define SHT_SYMTAB    2
  394. #define SHT_STRTAB    3
  395. #define SHT_RELA    4
  396. #define SHT_HASH    5
  397. #define SHT_DYNAMIC    6
  398. #define SHT_NOTE    7
  399. #define SHT_NOBITS    8
  400. #define SHT_REL        9
  401. #define SHT_SHLIB    10
  402. #define SHT_DYNSYM    11
  403. #define SHT_NUM        12
  404. #define SHT_LOPROC    0x70000000
  405. #define SHT_HIPROC    0x7fffffff
  406. #define SHT_LOUSER    0x80000000
  407. #define SHT_HIUSER    0xffffffff
  408.  
  409. /* sh_flags */
  410. #define SHF_WRITE    0x1
  411. #define SHF_ALLOC    0x2
  412. #define SHF_EXECINSTR    0x4
  413. #define SHF_MASKPROC    0xf0000000
  414.  
  415. /* special section indexes */
  416. #define SHN_UNDEF    0
  417. #define SHN_LORESERVE    0xff00
  418. #define SHN_LOPROC    0xff00
  419. #define SHN_HIPROC    0xff1f
  420. #define SHN_ABS        0xfff1
  421. #define SHN_COMMON    0xfff2
  422. #define SHN_HIRESERVE    0xffff
  423.  
  424. typedef struct {
  425.   Elf32_Word    sh_name;
  426.   Elf32_Word    sh_type;
  427.   Elf32_Word    sh_flags;
  428.   Elf32_Addr    sh_addr;
  429.   Elf32_Off    sh_offset;
  430.   Elf32_Word    sh_size;
  431.   Elf32_Word    sh_link;
  432.   Elf32_Word    sh_info;
  433.   Elf32_Word    sh_addralign;
  434.   Elf32_Word    sh_entsize;
  435. } Elf32_Shdr;
  436.  
  437. typedef struct elf64_shdr {
  438.   Elf32_Word sh_name;        /* Section name, index in string tbl (yes Elf32) */
  439.   Elf32_Word sh_type;        /* Type of section (yes Elf32) */
  440.   Elf64_Word sh_flags;        /* Miscellaneous section attributes */
  441.   Elf64_Addr sh_addr;        /* Section virtual addr at execution */
  442.   Elf64_Off sh_offset;        /* Section file offset */
  443.   Elf64_Word sh_size;        /* Size of section in bytes */
  444.   Elf32_Word sh_link;        /* Index of another section (yes Elf32) */
  445.   Elf32_Word sh_info;        /* Additional section information (yes Elf32) */
  446.   Elf64_Word sh_addralign;    /* Section alignment */
  447.   Elf64_Word sh_entsize;    /* Entry size if section holds table */
  448. } Elf64_Shdr;
  449.  
  450. #define    EI_MAG0        0        /* e_ident[] indexes */
  451. #define    EI_MAG1        1
  452. #define    EI_MAG2        2
  453. #define    EI_MAG3        3
  454. #define    EI_CLASS    4
  455. #define    EI_DATA        5
  456. #define    EI_VERSION    6
  457. #define    EI_PAD        7
  458.  
  459. #define    ELFMAG0        0x7f        /* EI_MAG */
  460. #define    ELFMAG1        'E'
  461. #define    ELFMAG2        'L'
  462. #define    ELFMAG3        'F'
  463. #define    ELFMAG        "¥177ELF"
  464. #define    SELFMAG        4
  465.  
  466. #define    ELFCLASSNONE    0        /* EI_CLASS */
  467. #define    ELFCLASS32    1
  468. #define    ELFCLASS64    2
  469. #define    ELFCLASSNUM    3
  470.  
  471. #define ELFDATANONE    0        /* e_ident[EI_DATA] */
  472. #define ELFDATA2LSB    1
  473. #define ELFDATA2MSB    2
  474.  
  475. #define EV_NONE        0        /* e_version, EI_VERSION */
  476. #define EV_CURRENT    1
  477. #define EV_NUM        2
  478.  
  479. /* Notes used in ET_CORE */
  480. #define NT_PRSTATUS    1
  481. #define NT_PRFPREG    2
  482. #define NT_PRPSINFO    3
  483. #define NT_TASKSTRUCT    4
  484.  
  485. /* Note header in a PT_NOTE section */
  486. typedef struct elf32_note {
  487.   Elf32_Word    n_namesz;    /* Name size */
  488.   Elf32_Word    n_descsz;    /* Content size */
  489.   Elf32_Word    n_type;        /* Content type */
  490. } Elf32_Nhdr;
  491.  
  492. /* Note header in a PT_NOTE section */
  493. /*
  494.  * For now we use the 32 bit version of the structure until we figure
  495.  * out whether we need anything better.  Note - on the Alpha, "unsigned int"
  496.  * is only 32 bits.
  497.  */
  498. typedef struct elf64_note {
  499.   Elf32_Word n_namesz;    /* Name size */
  500.   Elf32_Word n_descsz;    /* Content size */
  501.   Elf32_Word n_type;    /* Content type */
  502. } Elf64_Nhdr;
  503.  
  504. #if ELF_CLASS == ELFCLASS32
  505.  
  506. extern Elf32_Dyn _DYNAMIC [];
  507. #define elfhdr        elf32_hdr
  508. #define elf_phdr    elf32_phdr
  509. #define elf_note    elf32_note
  510.  
  511. #else
  512.  
  513. extern Elf64_Dyn _DYNAMIC [];
  514. #define elfhdr        elf64_hdr
  515. #define elf_phdr    elf64_phdr
  516. #define elf_note    elf64_note
  517.  
  518. #endif
  519.  
  520.  
  521. #endif /* _LINUX_ELF_H */
  522.